/*
 * Flashlib - QB9 common Flash library
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package com.qb9.flashlib.ui
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	/**
	 * A simple Sprite with a text label.  Use the <code>ButtonManager</code>
	 * class to add interactivity to the button.
	 *
	 * @see ButtonManager
	 */
	public class QuickButton extends Sprite
	{
		protected var tf:TextField;
		
		/**
		 * Create a QuickButton instance.
		 *
		 * @param label Text label for the button.
		 */
		public function QuickButton(label:String = "button")
		{
			this.init();
			this.label = label;
			this.mouseChildren = false;
		}

		protected function init():void
		{
			this.tf = new TextField();
			this.tf.defaultTextFormat = new TextFormat("_sans");
			this.tf.selectable = false;
			this.tf.autoSize = TextFormatAlign.LEFT;
			this.addChild(this.tf);
		}

		/**
		 * Button text label.
		 */
		public function get label():String
		{
			return this.tf.text;
		}

		/**
		 * @private
		 */
		public function set label(s:String):void
		{
			this.tf.text = s;
			this.tf.x = 10;
			this.tf.y = 5;
			this.updateFrame();
		}

		protected function updateFrame():void
		{
			this.graphics.clear();
			this.graphics.lineStyle(1);
			this.graphics.beginFill(0xa0a0a0);
			this.graphics.drawRect(0, 0, this.tf.textWidth + 2 * this.tf.x, this.tf.textHeight + 2 * this.tf.y)
			this.graphics.endFill();
		}
	}
}

